import stripe

stripe.api_key = "sk_test_51Ogsw5B0IyqaSJBrwczlr820jnmvA1qQQGoLZ2XxOsIzikpmXo4pRLjw4XVMTEBR8DdVTYySiAv1XX53Zv5xqynF00GfMqttFd"


class InvoiceService:
    def __init__(self):
        pass

    def get_subscription_invoices(self, subscription_id):
        try:
            # 查询订阅关联的所有账单
            invoices = stripe.Invoice.list(subscription=subscription_id)
            return [
                {
                    "invoice_id": inv.id,
                    "amount": inv.amount_paid / 100,  # 支付金额
                    "status": inv.status,  # paid（已支付）、open（未支付）等
                    # "paid_at": inv.paid_at  # 支付时间（时间戳）
                }
                for inv in invoices.data
            ]
        except stripe.error.StripeError as e:
            return {"error": str(e)}


if __name__ == '__main__':
    service = InvoiceService()
    print(service.get_subscription_invoices(subscription_id="sub_1S1P2FB0IyqaSJBreZ6C6Dig"))
